import request from "@/axios/axios.ts";
import {useStore} from '@/pinia'

const store = useStore()

import type {
    BigTableCRUD,
    SmallTableCRUD,
    BigOrSmallStopUse, RecordTableCRUD, LocationCheck
} from './type.ts'

enum API1 {
    BIG_CRUD_URL = '/first/big_list_crud',
    SMALL_CRUD_URL = '/first/small_list_crud',
    RECORD_CRUD_URL = '/first/record_list_crud',
    BIG_OR_SMALL_STOP_USE = '/first/big_or_small_stop_use',
    LocationCheck = '/first/location_check',
}

enum API2 {
    BIG_CRUD_URL = '/second/big_list_crud',
    SMALL_CRUD_URL = '/second/small_list_crud',
    RECORD_CRUD_URL = '/second/record_list_crud',
    BIG_OR_SMALL_STOP_USE = '/second/big_or_small_stop_use',
    LocationCheck = '/second/location_check',
}
enum API3 {
    BIG_CRUD_URL = '/first_new/big_list_crud',
    SMALL_CRUD_URL = '/first_new/small_list_crud',
    RECORD_CRUD_URL = '/first_new/record_list_crud',
    BIG_OR_SMALL_STOP_USE = '/first_new/big_or_small_stop_use',
    LocationCheck = '/first_new/location_check',
}

// 大类表（big）CRUD接口
export const reqBigList = (data: BigTableCRUD): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.BIG_CRUD_URL, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.BIG_CRUD_URL, data)
    else
        return request.post<any, any>(API3.BIG_CRUD_URL, data)
}

// 小类表（small）CRUD接口
export const reqSmallList = (data: SmallTableCRUD): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.SMALL_CRUD_URL, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.SMALL_CRUD_URL, data)
    else
        return request.post<any, any>(API3.SMALL_CRUD_URL, data)
}

// 小类表的库位管理和时间段未修改统计
export const reqLocationCheck = (data: LocationCheck): Promise<any> => {
    if(store.axios_path === '1')
        return request.post<any, any>(API1.LocationCheck, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.LocationCheck, data)
    else
        return request.post<any, any>(API3.LocationCheck, data)
}

// 明细表（record）CRUD接口
export const reqRecordList = (data: RecordTableCRUD): Promise<any> => {
    console.log('store.axios_path', store.axios_path)
    if (store.axios_path === '1')
        return request.post<any, any>(API1.RECORD_CRUD_URL, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.RECORD_CRUD_URL, data)
    else
        return request.post<any, any>(API3.RECORD_CRUD_URL, data)
}

// 大类和小类使用情况更改
export const reqBigStopUse = (data: BigOrSmallStopUse): Promise<any> => {
    if (store.axios_path === '1')
        return request.post<any, any>(API1.BIG_OR_SMALL_STOP_USE, data)
    else if(store.axios_path === '2')
        return request.post<any, any>(API2.BIG_OR_SMALL_STOP_USE, data)
    else
        return request.post<any, any>(API3.BIG_OR_SMALL_STOP_USE, data)
}

